package 最后24大厂仿真;

import java.util.PriorityQueue;
import java.util.Queue;

public class FZ4牛奶供应问题 {
    static class Solution {
        public int animalTaskScheduler(int[] taskDurations, int capacity) {
            Queue<Integer>queue = new PriorityQueue<>();
            for (int i = 0; i < taskDurations.length; i++) {
                if(queue.size() < capacity){
                    queue.add(taskDurations[i]);
                }else{
                    int t = queue.poll();
                    t += taskDurations[i];
                    queue.add(t);
                }
            }
            int res = 0;
            while(!queue.isEmpty()){
                res = queue.poll();
            }
            return res;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] taskDurations = {3, 2, 4, 1, 5};
        int capacity = 3;
        System.out.println(solution.animalTaskScheduler(taskDurations,capacity));
    }
}
